package com.esoon.service.impl;

import com.esoon.dao.ThirdpartyPhoneAreaDao;
import com.esoon.entity.MyPhoneArea;
import com.esoon.entity.ThirdpartyPhoneArea;
import com.esoon.entity.ThirdpartyPhoneAreaExample;
import com.esoon.service.ThirdpartyPhoneAreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ThirdpartyPhoneAreaServiceImpl
 * @Description TODO
 * @Author 2020/9/23 13:50
 * @Version 1.0
 **/

@Service("ThirdpartyPhoneAreaServiceImpl")
public class ThirdpartyPhoneAreaServiceImpl implements ThirdpartyPhoneAreaService {
  @Resource
  private ThirdpartyPhoneAreaDao thirdpartyPhoneAreaDao;

    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(ThirdpartyPhoneAreaServiceImpl.class);
    }


    /*
     * @Author Jack
     * @Description //TODO 目前IVR系统，仅需要判断电话号码是否为新疆地区的，如果是，则返回1 如果不是新疆地区的，返回0
     *                 csr地区规则为使用电话号码前7位作为phone字段的值，查询地址表，以phone做判断，查询省
     * @Date 16:45 2020/9/24
     * @Param
     * @return
     *
     **/

    @Override
    public String selectByPhoneNumber(String oldPhone,String tenantCode) {
        String result = "0";
        String phone = oldPhone.substring(0,7);

       try {
           String province = thirdpartyPhoneAreaDao.selectByPhoneNumber(phone,tenantCode);
           if (oldPhone.length()!= 11){
               logger.error("电话号码长度不是11位");
               result = "500";
           }
               if (province.equals("新疆")){
               result = "1";
           }
       }catch (Exception e){
           logger.error(e.toString());
           result= "0";
       }
        return result;
    }

    @Override
    public MyPhoneArea selectArea(String oldPhone,String tenantCode) {
        String phone = oldPhone.substring(0,7);
        if (oldPhone.length() == 11 ){
           return thirdpartyPhoneAreaDao.selectArea(phone,tenantCode);
        }else {
            return null;
        }
    }
}
